local skel = fk.CreateSkill {
  name = "emo__kuangre",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__kuangre"] = "狂热",
  [":emo__kuangre"] = "锁定技，任何【杀】结算后，本回合你再使用X张牌，摸X张牌并重置你本阶段的【杀】次数。（X为本回合【杀】被使用的次数）",
  ["@emo__kuangre-turn"] = "狂热",
}

skel:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and data.card.trueName == "slash"
  end,
  on_use = function (self, event, target, player)
    local room = player.room
    local num = #room.logic:getEventsOfScope(GameEvent.UseCard, 99, function(e)
      local use = e.data
      return use.card.trueName == "slash"
    end, Player.HistoryTurn)
    if num == 0 then return end
    room:addTableMark(player, "@emo__kuangre-turn", num)
    room:addTableMark(player, "emo__kuangre-turn", num)
  end,
})

skel:addEffect(fk.CardUsing, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player
    and #player:getTableMark("@emo__kuangre-turn") > 0 and #player:getTableMark("emo__kuangre-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player)
    local room = player.room
    local UImark = player:getTableMark("@emo__kuangre-turn")
    local mark = player:getTableMark("emo__kuangre-turn")
    if #mark == 0 or UImark == 0 then return end
    local draws = {}
    for i = #UImark, 1, -1 do
      local num = UImark[i]
      if num > 1 then
        UImark[i] = num - 1
      else
        table.insert(draws, table.remove(mark, i))
        table.remove(UImark, i)
      end
    end
    room:setPlayerMark(player, "emo__kuangre-turn", #mark > 0 and mark or 0)
    room:setPlayerMark(player, "@emo__kuangre-turn", #UImark > 0 and UImark or 0)
    for _, num in ipairs(draws) do
      if player.dead then break end
      player:drawCards(num, skel.name)
      player:setCardUseHistory("slash", 0, Player.HistoryPhase)
    end
  end,
})


return skel
